import mitt from 'mitt'
export class TextModel {
    spacers_ = ''
    emitter = mitt()
    constructor(){
    }
    getSpacers(): string {
        return this.spacers_;
    }
    textChangeEmit_(){ //修改完文本数据层模型 派发通知出去修改视图
        this.emitter.emit('text-change')
    }
    insert(spcerIndex:number, spacers:string){
        const oldSpacers = this.spacers_
        this.spacers_ = oldSpacers.slice(0,spcerIndex) + spacers + oldSpacers.slice(spcerIndex)
        this.textChangeEmit_()
    }
    remove(anchor: number ,focus: number ){
        const oldSpacers = this.spacers_
        if(anchor>focus) [anchor,focus] = [focus,anchor]
        this.spacers_ = oldSpacers.slice(0,anchor) + oldSpacers.slice(focus)
        this.textChangeEmit_()
    }

}